package com.company.serialization;

import java.io.Serializable;
import java.nio.ByteBuffer;

/**
 * @description: some desc
 * @author: ruoan
 * @date: 2021/1/1 18:27
 */
public class Student implements Serializable {
    private static final long serialVersionUID = -7107707374857353755L;
    private String userName;
    private int userId;

    public Student() {

    }

    public Student(String userName, int userId) {
        this.userName = userName;
        this.userId = userId;
    }


    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    // ByteBuffer 序列化
    public byte[] codeC(){

        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        byte[] value = this.userName.getBytes();
        byteBuffer.putInt(value.length);
        byteBuffer.put(value);
        byteBuffer.putInt(this.userId);
        byteBuffer.flip();
        value = null;
        byte[] result = new byte[byteBuffer.remaining()];
        byteBuffer.get(result);
        return result;
    }




}
